import i18n from '@/i18n'
import { ApiProperty } from '@nestjs/swagger'
import { PageDto } from '../dto'

export class Page<T> {
  @ApiProperty({ description: i18n.t('lhy-core.entity.page.1215066-0') })
  current: number

  @ApiProperty({ description: i18n.t('lhy-core.entity.page.1215066-1') })
  size: number

  @ApiProperty({ description: i18n.t('lhy-core.entity.page.1215066-2') })
  totals: number

  @ApiProperty({ description: i18n.t('lhy-core.entity.page.1215066-3'), type: 'T', isArray: true })
  records: T[]

  /**
   * 跳过的条数
   */
  get skip() {
    return (this.current - 1) * this.size
  }

  /**
   * 读取的条数
   */
  get take() {
    return this.size
  }

  constructor(current: number, size?: number)
  constructor(pageDto: PageDto)
  constructor(arg0: number | PageDto, arg1?: number) {
    if (typeof arg0 === 'number') {
      this.current = arg0
      this.size = arg1 || 20
    } else {
      this.current = arg0.current
      this.size = arg0.size || 20
    }
  }
}
